<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 2,0,1 metric.
Algebra(2,0,1,()=>{

  // From "Doing euclidean plane geometry using projective geometric algebra" 
  // Charles Gunn - https://arxiv.org/abs/1501.06511, p21.
  
  //   Find and illustrate the unique direct isometry that takes (A,m) to (A2,m2)
  //   Note that ganja.js allows implementing this letter for letter like in
  //   the paper .. 

  var point      = (x,y)=>!(1e0 + x*1e1 + y*1e2),
      join       = (X,Y)=>(X&Y).Normalized,
      lerp       = (x,y,a)=>(1-a)*x+a*y;
      
  // Start with two points A and A2 (and a helper)      
  var A = point(-1, -1), A2 = point(0.9, -0.4), B = point(0, 1), B2 = point(0, 1),
  
  // Form the lines m and m2 using these points.
      m = ()=>join(A, B), m2 = ()=>join(B2, A2),
  
  // Find intersection of m and m2 and line through a and a2    
      M = ()=>m ^ m2, a = ()=>join(A, A2),
      
  // Find the midpoint between A and A2 and the orthogonal line through it.      
      Am = ()=>A + A2, r= ()=>(a | Am).Normalized,
      
  // Find the line between m and m2 and cut that with r to find the center of our isometry      
      c = ()=>m - m2, C = ()=>r ^ c,
      
  // Construct the transformation as a rotation around C. (or translation if C is ideal)       
      s = ()=>join(A, C), g = ()=>r * s,
  
  // Interpolate the isometry to illustrate the solution. 
      lines = [...Array(100)].map((x,xi)=>()=>lerp(Math.sign(g().s), g, xi*0.01) >>> m);

  // Reproduce the graph from the paper
  document.body.appendChild(this.graph([
    0xCCDDDD, ...lines,
    0x00AA88, m,"m &rarr;", m2,"m' &rarr;", 
    0x224488, [A,A2],
    0x8822FF, c, "c",
    0x882288, r, "r",
    0x884422, s, "s", 
    0x224488, A, "A", A2, "A'",
    0x00AA88, M, "M", C, "C", B, B2,
  ],{lineWidth:2}));
  
});
</SCRIPT></BODY>